set nocompatible              " 去除VI一致性,必须要添加
filetype off                  " 必须要添加

" 设置包括vundle和初始化相关的runtime path
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" 另一种选择, 指定一个vundle安装插件的路径
"call vundle#begin('~/some/path/here')

" 让vundle管理插件版本,必须
Plugin 'VundleVim/Vundle.vim'

" 我的插件
Plugin 'preservim/nerdtree'
" 在needtree中显示文件图标
Plugin 'mhinz/vim-startify'
Plugin 'tomasr/molokai'

Plugin 'powerline/powerline-fonts'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'enricobacis/vim-airline-clock'
Plugin 'ryanoasis/vim-devicons'

Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
" Plugin 'voldikss/vim-floaterm'
" Plugin 'voldikss/fzf-floaterm'
Plugin 'jiangmiao/auto-pairs'
" 编辑markdown的插件
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
" 该插件虽然可以在浏览器中实时查看markdown的效果, 但是由很多语法不支持,
" 体验并不好, 还是禁用掉吧
" Plugin 'suan/vim-instant-markdown'
" vim自动生成Toc的插件, plasticboy/vim-markdown已经有toc功能了, 这个功能比较多余
" Plugin 'mzlogin/vim-markdown-toc'

""" vim的git插件-start
" 使vim支持调用git
Plugin 'tpope/vim-fugitive'
" 使vim在行号上显示修改状态
Plugin 'airblade/vim-gitgutter'
" 使vim可以浏览版本库
Plugin 'junegunn/gv.vim'
" 使nredtree中的文件也可以显示git状态
Plugin 'Xuyuanp/nerdtree-git-plugin'
""" vim的git插件-end

Plugin 'neoclide/coc.nvim'

" vim的包围插件
Plugin 'tpope/vim-surround'

"真彩色
Plugin 'tpope/vim-sensible'
"彩虹括号
Plugin 'kien/rainbow_parentheses.vim'

Plugin 'altercation/solarized'
Plugin 'altercation/vim-colors-solarized'

"显示文件修改痕迹
Plugin 'chrisbra/changesPlugin'

" 你的所有插件需要在下面这行之前
call vundle#end()            " 必须
filetype plugin indent on    " 必须 加载vim自带和插件相应的语法和文件类型相关脚本
" 忽视插件改变缩进,可以使用以下替代:
"filetype plugin on
"
" 常用的命令
" :PluginList       - 列出所有已配置的插件
" :PluginInstall       - 安装插件,追加 `!` 用以更新或使用 :PluginUpdate
" :PluginSearch foo - 搜索 foo ; 追加 `!` 清除本地缓存
" :PluginClean      - 清除未使用插件,需要确认; 追加 `!` 自动批准移除未使用插件
"
" 查阅 :h vundle 获取更多细节和wiki以及FAQ
" 将你自己对非插件片段放在这行之后


" 使不生成备份文件和swap文件
set noundofile
set nobackup
set noswapfile

" 设置文件编码
set fileencodings=utf-8,gbk,gb2312,cp936,big5
set termencoding=utf-8
set encoding=utf-8

" 设置字体
"set guifont=Powerline_Consolas:JetBrains_Mono:h11:cANSI:qDRAFT
set guifont=JetBrainsMono_Nerd_Font_Mono:h13

" 关闭toolbar和menubar
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
        \set guioptions-=T <Bar>
        \set guioptions-=m <bar>
    \else <Bar>
        \set guioptions+=T <Bar>
        \set guioptions+=m <Bar>
    \endif<CR>
	
" 语法高亮
syntax enable

" 显示模式
set showmode

" 显示命令
set showcmd

" 自动缩进
set autoindent

" 智能缩进
set smartindent

" Tab的空格数
set tabstop=4
" 当设置成 expandtab 时，缩进用空格来表示，noexpandtab 则是用制表符表示一个缩进
set expandtab 

" 自动缩进长度
set shiftwidth=4
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格

set nowrapscan " 禁止在搜索到文件两端时重新搜索

" 显示状态栏
set laststatus=2	

" windows关闭gvim下的警告声
set vb t_vb=
au GuiEnter * set t_vb=

" 高亮当前行
set cursorline

" 显示行号
set number

" 设置molokai主题, 需要先安装该插件
"colorscheme molokai

" 启用退格键, 没有这个将会导致无法删除
set backspace=2

" 模拟idea: 使按下Alt-1组合键显示隐藏文件窗口
map <M-1> :NERDTreeMirror<CR>
map <M-1> :NERDTreeToggle<CR>
" 隐藏滚动条, 不设置这个的话打开NERDTree之后将会在左侧显示滚动条, 非常不好看
set guioptions-=L 
" 显示bookmark
let NERDTreeShowBookmarks=1
" 修改默认箭头符号
let g:NERDTreeDirArrowExpandable = '»'
let g:NERDTreeDirArrowCollapsible = '›'

" 隐藏滚动条
set guioptions-=r

" 配置fzf的快捷键
nnoremap <silent> <Leader>C        :Colors<CR>
nnoremap <silent> <Leader>b  	   :Buffers<CR>
nnoremap <silent> <Leader>f 	   :Files<CR>
nnoremap <silent> <Leader>l        :Lines<CR>
nnoremap <silent> <Leader>ag       :Ag <C-R><C-W><CR>
nnoremap <silent> <Leader>AG       :Ag <C-R><C-A><CR>
xnoremap <silent> <Leader>ag       y:Ag <C-R>"<CR>
nnoremap <silent> <Leader>`        :Marks<CR>
command! -bang -nargs=* Ag
  \ call fzf#vim#ag(<q-args>,
  \                 <bang>0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)
nnoremap <silent> <Leader>A :Ag<CR>

" This is the default option:
"   - Preview window on the right with 50% width
"   - CTRL-/ will toggle preview window.
" - Note that this array is passed as arguments to fzf#vim#with_preview function.
" - To learn more about preview window options, see `--preview-window` section of `man fzf`.
let g:fzf_preview_window = ['right:50%', 'ctrl-/']

" Preview window on the upper side of the window with 40% height,
" hidden by default, ctrl-/ to toggle
let g:fzf_preview_window = ['up:40%:hidden', 'ctrl-/']

" Empty value to disable preview window altogether
let g:fzf_preview_window = []

" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1

" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'

" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'

" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'

" 设置高亮
syntax on

" 搜索设置高亮
set hlsearch
set incsearch " 输入搜索内容时就显示搜索结果

set noerrorbells " 关闭错误信息响铃

set showmatch " 插入括号时，短暂地跳转到匹配的对应括号
set hidden " 允许在有未保存的修改时切换缓冲区，此时的修改由 vim 负责保存

set smartindent " 开启新行时使用智能自动缩进
set backspace=indent,eol,start
" 不设定在插入状态无法用退格键和 Delete 键删除回车符
set cmdheight=1 " 设定命令行的行数为 1


" 设置在状态行显示的信息
"set foldenable " 开始折叠
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
setlocal foldlevel=1 " 设置折叠层数为
" set foldclose=all " 设置为自动关闭折叠 
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" 用空格键来开关折叠

""" markdown配置-start
" 使能数学公式, 默认情况下是关闭的
let g:vim_markdown_math = 1
""" markdown配置-start

""" Xuyuanp/nerdtree-git-plugin 插件设置-start
let g:NERDTreeGitStatusIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }
""" Xuyuanp/nerdtree-git-plugin 插件设置-end

" 解决menu bar中文乱码
if(has("win32") || has("win95") || has("win64") || has("win7") || has("win10"))
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim
endif
set ignorecase

""" idea key short setting
" git pull
map <C-t> :Git pull<CR>
" git push
map <C-k> :Git push<CR>

" 解决consle输出乱码
"set termencoding = cp936  
" 设置中文提示
language messages zh_CN.utf-8 
" 设置中文帮助
set helplang=cn
" 设置为双字宽显示，否则无法完整显示如:☆
set ambiwidth=double
" 总是显示状态栏 
let laststatus = 2

""" vim-airline and powerline-fonts setting
let g:airline_powerline_fonts = 1   " 使用powerline打过补丁的字体
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif
" setting clold_theme
let g:airline_theme='solarized'
"let g:airline_theme='molokai'

 " 开启tabline
let g:airline#extensions#tabline#enabled = 1      "tabline中当前
let g:airline#extensions#tabline#left_sep = ' '   "buffer两端的分隔字符
let g:airline#extensions#tabline#left_alt_sep = '|'      "tabline中
let g:airline#extensions#tabline#buffer_nr_show = 1      "buffer显示编号
let g:airline#extensions#whitespace#enabled = 0 "控制不显示whitespace信息

let g:airline_left_sep = ' '
let g:airline_left_alt_sep = '▶'
let g:airline_right_sep = ' '
let g:airline_right_alt_sep = '◀'
let g:airline_symbols.crypt = '🔒'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.maxlinenr = '㏑'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.spell = 'Ꞩ'
let g:airline_symbols.notexists = 'Ɇ'
let g:airline_symbols.whitespace = 'Ξ'

" 关闭当前 buffer
noremap <F4> :w<CR>:bd<CR>
"<leader>1~9 切到 buffer1~9
map <leader>1 :b 1<CR>
map <leader>2 :b 2<CR>
map <leader>3 :b 3<CR>
map <leader>4 :b 4<CR>
map <leader>5 :b 5<CR>
map <leader>6 :b 6<CR>
map <leader>7 :b 7<CR>
map <leader>8 :b 8<CR>
map <leader>9 :b 9<CR>

" 映射切换buffer的键位
nnoremap [b :bp<CR>
nnoremap ]b :bn<CR>

""" enricobacis/vim-airline-clock setting
"let g:airline#extensions#clock#auto = 0  关闭
let g:airline#extensions#clock#format = '%H:%M:%S'


" Python 文件的一般设置，比如不要 tab 等
autocmd FileType python set tabstop=4 shiftwidth=4 expandtab
autocmd FileType python map <F12> :!python %<CR>

let g:solarized_termtrans  = 1         " 使用 termnal 背景
let g:solarized_visibility = "high"    " 使用 :set list 显示特殊字符时的高亮级别
" GUI 模式浅色背景，终端模式深色背景
if has('gui_running')
    set background=light
else
    set background=dark
endif
" 主题设置为 solarized
colorscheme solarized

let g:gitgutter_terminal_reports_focus = 0
nnoremap <leader>gd :GitGutterToggle<CR>

" 控制markdown文件默认不折叠, 当文件较大时折叠后较难看
let g:vim_markdown_folding_disabled = 1
